package com.cpecc.dao.wuzi;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.wuzi.TuPian;

@Repository
public class TuPianDao {
	
	@Resource
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public void save(TuPian tuPian){
		Session session=sessionFactory.getCurrentSession();
		session.save(tuPian);
		session.flush();
	}
	
	public TuPian get(String id){
		return (TuPian) sessionFactory.getCurrentSession().get(TuPian.class, id);
	}
	
	public boolean delete(String id){
		String hql = "delete TuPian u where u.id=?";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, id);		
		return (query.executeUpdate() > 0);
	}

}
